package no.saiboten.drumcalendar.user;

import java.util.logging.Logger;

import org.springframework.stereotype.Component;

import com.googlecode.objectify.NotFoundException;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

@Component
public class WinnerDao {

	Objectify ofy;

	private final Logger LOGGER = Logger.getLogger(WinnerDao.class.getName());

	public WinnerDao() {
		ObjectifyService.register(Winners.class);
		ofy = ObjectifyService.begin();
	}

	public Winners getWinners() {
		Winners winners = null;
		try {
			winners = ofy.get(Winners.class, "winner");
		} catch (NotFoundException u) {
			LOGGER.fine("Winners not saved yet: " + u);
		}

		if (winners == null) {
			winners = new Winners();
			winners.setKey("winner");
			ofy.put(winners);
		}
		return winners;
	}

	public void saveWinners(Winners winners) {
		ofy.put(winners);
	}

}
